#!/bin/bash
version=$(date -d "8 hour" -u +%y.%m.%d.%H)
cd ~/app-root/data/github-sh/xpi/acvaa/
wget --no-check-certificate https://raw.githubusercontent.com/rasso1/youkuantiads/master/AntiChinaVideoAds_with_player.rdf
if diff -q AntiChinaVideoAds_with_player.rdf AntiChinaVideoAds_with_player2.rdf; then
   rm -f AntiChinaVideoAds_with_player.rdf
else
   mv -f AntiChinaVideoAds_with_player.rdf AntiChinaVideoAds_with_player2.rdf
   grep -o http.*\.xpi AntiChinaVideoAds_with_player2.rdf >./download.txt
   wget --no-check-certificate -i download.txt --output-document=acvaa.zip
   unzip acvaa.zip -d do/
   rm -f acvaa.zip download.txt
      rm -rf ~/app-root/data/gh-pages/swf/*
      mv -f acvaa/content/swf/*.swf ~/app-root/data/gh-pages/swf/
   cd ~/app-root/data/github-sh/xpi/acvaa/
   if ! diff -q acvaa/content/AntiChinaVideoAds.js AntiChinaVideoAds.js; then
      sed -i "/'re':/s#http:#https?:#" acvaa/content/AntiChinaVideoAds.js
      cp -f acvaa/content/AntiChinaVideoAds.js AntiChinaVideoAds.js
      sed -n '/SITES\:/,$p' AntiChinaVideoAds.js >2.txt
      cat 1b.txt 2.txt 3.txt > YoukuAntiADs.uc.js
      sed -i "8c\// @version         ${version}" YoukuAntiADs.uc.js
      sed -i "s#'chrome:\/\/AntiChinaVideoAds\/content\/swf\/#refD \+ '#" YoukuAntiADs.uc.js
      mv -f YoukuAntiADs.uc.js ~/app-root/runtime/repo/uc脚本/YoukuAntiADs/YoukuAntiADs.uc.js
      cat 1c.txt 2.txt 3.txt > YoukuAntiADs.uc.js
      sed -i "8c\// @version         ${version}" YoukuAntiADs.uc.js
      sed -i "s#'chrome:\/\/AntiChinaVideoAds\/content\/swf\/#refD \+ '#" YoukuAntiADs.uc.js
      mv -f YoukuAntiADs.uc.js ~/app-root/runtime/repo/uc脚本/YoukuAntiADs/YoukuAntiADsL.uc.js
      ~/app-root/data/github-sh/log/log.sh "YoukuAntiADs.uc.js 更新"
      sed -i 's#chrome:\/\/AntiChinaVideoAds\/content#http:\/\/minggo\.coding\.io#' acvaa/content/AntiChinaVideoAds.js
      cp -f 4.txt acvaa/install.rdf
      sed -i "s#15\.08\.01\.20#${version}#" acvaa/install.rdf
      cd do/
      zip -r acvaa.xpi *
      latest=$(cat ../latest.txt)
      mv -f acvaa.xpi ~/app-root/runtime/repo/扩展/acvaa-${version}.xpi
      rm -rf ~/app-root/runtime/repo/扩展/acvaa-${latest}.xpi ../2.txt ../do
      echo ${latest} >../latest.txt
      ~/app-root/data/github-sh/log/log.sh "acvaa-${version}.xpi 更新"
   fi
fi